﻿using System;
using UnityEngine;

namespace RenderHeads.Media.AVProVideo.Demos
{
	// Token: 0x02000012 RID: 18
	public class VideoTrigger : MonoBehaviour
	{
		// Token: 0x06000052 RID: 82 RVA: 0x000040FC File Offset: 0x000022FC
		private void OnTriggerEnter(Collider other)
		{
			if (this._mediaPlayer != null)
			{
				this._mediaPlayer.Play();
				this._fadeDirection = 1f;
			}
		}

		// Token: 0x06000053 RID: 83 RVA: 0x00004128 File Offset: 0x00002328
		private void OnTriggerExit(Collider other)
		{
			if (this._mediaPlayer != null)
			{
				this._fadeDirection = -1f;
			}
		}

		// Token: 0x06000054 RID: 84 RVA: 0x00004148 File Offset: 0x00002348
		private void Update()
		{
			if (this._fadeDirection != 0f)
			{
				float num = 1000f / this._fadeTimeMs;
				this._fade += Time.deltaTime * this._fadeDirection * num;
				if (this._fade <= 0f)
				{
					this._mediaPlayer.Rewind(true);
					this._fadeDirection = 0f;
				}
				else if (this._fade >= 1f)
				{
					this._fadeDirection = 0f;
				}
				this._fade = Mathf.Clamp01(this._fade);
				if (this._mediaPlayer != null && this._mediaPlayer.Control != null)
				{
					this._mediaPlayer.Control.SetVolume(this._fade);
				}
			}
		}

		// Token: 0x04000045 RID: 69
		[SerializeField]
		private MediaPlayer _mediaPlayer;

		// Token: 0x04000046 RID: 70
		[SerializeField]
		private float _fadeTimeMs = 500f;

		// Token: 0x04000047 RID: 71
		private float _fade;

		// Token: 0x04000048 RID: 72
		private float _fadeDirection;
	}
}
